$(function () {
	
	departmentValidator();
	
	if($("#popuperrorMessage").val()==='true'){
		$('#department_add_and_update').modal('show');
	}
	
    $('input[type="text"]').click(function(){
    	$(this).next().text("");
    });
        
    $("body").on("click",'a[name="show"]',function(){
    	var depUuid=$(this).attr("id");
    	var url="/department/getDepartment";
    	if(!isEmpty(depUuid)){
			var data = {
						'depUuid' :depUuid,
						};
			var datas=ajaxUtil(url, data, false, "","");
			if(!isEmpty(datas)){
				$("#depUuid").val(datas.data.depUuid);
				$("#depName").val(datas.data.depName);
				$("#depTele").val(datas.data.depTele);
				$('#department_add_and_update').modal('show');
			}else{
				$('#department_add_and_update').modal('hide');
			}
    	}
    });
       
    $("[name='cleanAll']").click(function(){
    	if($(this).attr("type")!="reset"){
    		$("#depUuid").val("");
    	}
    	$(":text").val("");
    	$("span[name='message']").text("");
    	$("#errorMessageAll").remove();
    	//Modal验证销毁重构
        $("#formdepartment").data('bootstrapValidator').destroy();
        $('#formdepartment').data('bootstrapValidator', null);
        departmentValidator();
    });
    
    $("body").on("click",'.example5-3-2', function(){
    	var depUuid=$(this).attr("id");
    	var menuUuid=$("input[name='menuUuid']").val();
    	var url="/department/delete?depUuid="+depUuid+"&menuUuid="+menuUuid;
    	deleteAlert(url);
    });
 });

function departmentValidator(){
	$("#formdepartment").bootstrapValidator({
		message : 'This value is not valid',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			depName : {
				message : '姓名验证失败',
				validators : {
					notEmpty : {
						message : '姓名不能为空'
					}
				}
			},
			depTele : {
				message : '手机号验证失败',
				validators : {
					notEmpty : {
						message : '手机号不能为空'
					},
					regexp : {
						regexp : /^1(3|4|5|7|8)\d{9}$/,
						message : '请输入正确的手机号'
					}
				}
			},
		},
		submitHandler : function(validator, form, submitButton) {
			alert("submit");
		}
	});
}

